//JavaScript Document
$(function () {
		$(".cur_postion").html("当前位置： [ "+sessionStorage.getItem("pmenuname")+" ] - [ "+sessionStorage.getItem("cmenuname")+" ]");
		
		//查询条件
		var strhtml_searchContent = '<div class="inline-block margin">'
			+'<span>标题:</span>'
			+'<input type="text" class="inputStyle_condition criglName"/>'
			+'</div>';
		$(".searchContent").html(strhtml_searchContent);
		//是否显示查询条件
		showSearchBox(false);
		
		var obj = {};//查询条件对象
		searchContent(obj);
		showList(obj,1);
		
		//修改
		$("body").delegate('.modifyit','click', function(){
			layer.open({
		        type: 2,
		        title: '修改',
		        scrollbar: false,
		        maxmin: true,
		        shadeClose: false, //点击遮罩关闭层
		        area : ['800px' , '520px'],
		        content: '../busi/integral_modify.html?id='+$(this).attr("data-id")
		    });
		});
		
		//全选
		$("body").delegate("input[name='checkboxAll']","click",function(){
			if($(this).attr("checked")){
				$("input[name='checkbox']").each(function(){
					$(this).attr("checked",true);
				});
			}else{
				$("input[name='checkbox']").each(function(){
					$(this).removeAttr("checked");
				});
			}
			
		});
		
		//tr高亮显示
		/*$("body").delegate(".trHighLight","mouseover",function(){
			$(this).find("td").css("background-color","#c1ebff");
		});*/
		$("body").delegate(".trHighLight","mouseleave",function(){
			$(this).find("td").css("background-color","#fff");
		});
		//tr高亮显示并显示图
		$("body").delegate(".trHighLight","mouseenter",function(){
			$(this).find("td").css("background-color","#c1ebff");
//			var imgurl = $(this).attr("data-imageurl");
//			if(imgurl != "#"){
//				var that = this;
//				$("<img/>").attr("src", imgurl).load(function() {
//						
//						var width = 150;
//						var realWidth = this.width;
//						var realHeight = this.height;
//						var height = realHeight/realWidth*width;
//						if(realWidth>=width){
//							var bannerimg = '<img id="bannerimg" src="'+imgurl+'" width="'+width+'px" height="'+height+'px" />';
//						}
//						else{//如果小于浏览器的宽度按照原尺寸显示
//							$("#bannerimg").css("width",realWidth+'px').css("height",realHeight+'px');
//							var bannerimg = '<img id="bannerimg" src="'+imgurl+'" width="'+realWidth+'px" height="'+realHeight+'px" />';
//						}
//						
//						layer.tips(bannerimg, that ,{
//						    tips: 3
//						});
//					});
//				}
		});
		
	});
	
	function showList(obj,pagenum){
		var aData = [{name:"<input type='checkbox' name='checkboxAll' value='checkbox' />",percent:"5"},
		             {name:"触发事件",percent:"15"},
		             {name:"所得收益",percent:"10"},
		             {name:"说明",percent:"25"},
		             {name:"创建日期",percent:"15"},
		             {name:"修改日期",percent:"15"},
		             {name:"操作",percent:"15"}];
		setTableHead(aData);
		var str = null; 
		getOData(str,"coreIntegral/find/all",{fn:function(oData){
					var strhtml_list = "";
					var arrData = oData.data;
					var ln = arrData.length;
					for(var i=0;i<ln;i++){
						strhtml_list += '<tr class="trHighLight">'
							+'<td>'+'<input type="checkbox" name="checkbox" value="checkbox" data-id="'+arrData[i].criglUuid+'"/>'+'</td>'
							+'<td>'+(arrData[i].criglName || "")+'</td>'
							+'<td>'+(arrData[i].criglScore || "0")+'</td>'
							+'<td>'+(arrData[i].criglDesc || "")+'</td>'
							+'<td>'+(arrData[i].criglCdate || "")+'</td>'
							+'<td>'+(arrData[i].criglCdate || "")+'</td>'
				       		+'<td>'
				            +'<a  class="p-edit modifyit" data-id="'+arrData[i].criglUuid+'">修改</a>'
				            +'</td>'
				            +'</tr>';
					}
					$(".tb-body").html(strhtml_list);
//					setTableFoot(oData.data,aData.length);
			}}
		);
	}
	
	function refreshList(){
		var obj = {};//查询条件对象
		searchContent(obj);
		showList(obj,parseInt($(".curpage").text()));
		layer.closeAll();
	}
	
	function searchContent(obj){
		obj.criglName = $(".criglName").val();
	}
